﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_PERMISSION.Base;

namespace ERP_RORZE_PRODUCT.Product.Deadline
{
    public partial class Frm_DeadlineCheckAdd : DevExpress.XtraEditors.XtraForm
    {
        ClsDeadlineDAO clsDeadlineDAO = new ClsDeadlineDAO();
        DataTable dt;
        clsDeadlineCheckTable b = new clsDeadlineCheckTable();
        public event EventHandler Reload;
        private LogUtils log;

        public Frm_DeadlineCheckAdd()
        {
            InitializeComponent();
            log = new LogUtils();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if(txtQty.Text =="")
            {
                MessageBox.Show("chưa nhập Qty. Vui lòng nhập lại");
            }
            else if(txtQty.Text != "")
            {
                    try
                    {
                        //int.Parse(txtQty.Text);
                        b.BOrderNo = cbBOderNo.Text;
                        b.Deadline = dateDeadline.Value;
                        b.PartID = cbPartID.Text;
                        b.Qty = int.Parse(txtQty.Text);
                        clsDeadlineDAO.Insert(b);

                        //write Log
                        log.Table = LogConstant.Table.Product.DeadlineCheck;
                        log.Task = LogConstant.Task.Insert;
                        log.Description = "BOrderNo: " + b.BOrderNo;
                        log.WriteLog();

                        MessageBox.Show("Đã cập nhật thành công");
                        Reload(sender, e);
                    }
                    catch(Exception ex)
                    {
                        MessageBox.Show("Qty phải là kiểu số nguyên! " + ex);
                    }
                
                
            }
        }

        private void Frm_DeadlineCheckAdd_Load(object sender, EventArgs e)
        {
            //
            dt = clsDeadlineDAO.GetAllBOder();
            cbBOderNo.DataSource = dt;
            cbBOderNo.DisplayMember = "BOderNo";
            cbBOderNo.ValueMember = "BOderNo";

            //sdfhg

            dt = clsDeadlineDAO.GetAllPartID();
            cbPartID.DataSource = dt;
            cbPartID.DisplayMember = "PartNo";
            cbPartID.ValueMember = "PartNo";
        }
    }
}